//
// Created by Snow on 2023/3/14.
//
#include<cstdio>
#include<cstdlib>
typedef int ElemType;
typedef struct qnode
{
    ElemType data;
    struct qnode *next;
}DataNode;
typedef struct
{
    DataNode *front;
    DataNode *rear;
}LinkQuNode;
void InitQueue(LinkQuNode *&q)
{
    q=(LinkQuNode *)malloc(sizeof(LinkQuNode));
    q->front=q->rear=nullptr;
}
void DestroyQueue(LinkQuNode *&q)
{
    DataNode *pre=q->front,*p;
    if(pre!=nullptr)
    {
        p=pre->next;
        while(p!=nullptr)
        {
            free(pre);
            pre=p;
            p=p->next;
        }
        free(pre);
    }
    free(q);
}
bool QueueEmpty(LinkQuNode *q)
{
    return(q->rear==nullptr);
}
void enQueue(LinkQuNode *&q,ElemType e)
{
    DataNode *p;
    p=(DataNode *)malloc(sizeof(DataNode));
    p->data=e;
    p->next=nullptr;
    if(q->rear==nullptr)
        q->front=q->rear=p;
    else
    {
        q->rear->next=p;
        q->rear=p;
    }
}
bool deQueue(LinkQuNode *&q,ElemType &e)
{
    if(q->rear==nullptr)
        return false;
    DataNode *r;
    r=q->front;
    if(q->rear==q->front)
        q->rear=q->front=nullptr;
    else
        q->front=r->next;
    e=r->data;
    free(r);
    return true;
}
int main()
{
    ElemType e,arr[]={1,2,3,4,5,6,7,'\0'};
    int i;
    LinkQuNode *q;
    InitQueue(q);
    if(QueueEmpty(q))printf("Yes\n");
    for(i=0;arr[i]!='\0';i++)
        enQueue(q,arr[i]);
    while(deQueue(q,e))printf("%d ",e);
    DestroyQueue(q);
    return 0;
}